#!/bin/bash

link=$1
file=$(basename $link)
expected_md5=$2
max_try=3
tried_time=0

ascp -k 1 -QT -l 300m -P 33001 \
-i /home/gjsx/.aspera/connect/etc/asperaweb_id_dsa.openssh $link .

actual_md5=$(md5sum "$file" | awk '{print $1}')

if [ "$actual_md5" == "$expected_md5" ]; then
    echo "$file: MD5 checksum verified"
else
    echo "$file: MD5 checksum mismatch"
    rm $file
    ascp.md5.sh $link $file $expected_md5
fi
